package com.java1412.tree.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.java1412.tree.domain.IsmModelTree;
import com.java1412.tree.service.IIsmModelTreeService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 模型文件树表Controller
 *
 * @author ruoyi
 * @date 2023-12-18
 */
@RestController
@RequestMapping("/tree/tree")
public class IsmModelTreeController extends BaseController
{
    @Autowired
    private IIsmModelTreeService ismModelTreeService;

    /**
     * 查询模型文件树表列表
     */
    @PreAuthorize("@ss.hasPermi('tree:tree:list')")
    @GetMapping("/list")
    public AjaxResult list(IsmModelTree ismModelTree)
    {
        List<IsmModelTree> list = ismModelTreeService.selectIsmModelTreeList(ismModelTree);
        return success(list);
    }

    /**
     * 导出模型文件树表列表
     */
    @PreAuthorize("@ss.hasPermi('tree:tree:export')")
    @Log(title = "模型文件树表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IsmModelTree ismModelTree)
    {
        List<IsmModelTree> list = ismModelTreeService.selectIsmModelTreeList(ismModelTree);
        ExcelUtil<IsmModelTree> util = new ExcelUtil<IsmModelTree>(IsmModelTree.class);
        util.exportExcel(response, list, "模型文件树表数据");
    }

    /**
     * 获取模型文件树表详细信息
     */
    @PreAuthorize("@ss.hasPermi('tree:tree:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ismModelTreeService.selectIsmModelTreeById(id));
    }

    /**
     * 新增模型文件树表
     */
    @PreAuthorize("@ss.hasPermi('tree:tree:add')")
    @Log(title = "模型文件树表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IsmModelTree ismModelTree)
    {
        return toAjax(ismModelTreeService.insertIsmModelTree(ismModelTree));
    }


    /**
     * 批量新增模型文件树表
     */
    @PreAuthorize("@ss.hasPermi('tree:tree:adds')")
    @Log(title = "模型文件树表", businessType = BusinessType.INSERT)
    @PostMapping(value = "/adds")
    public AjaxResult adds(@RequestBody List<IsmModelTree> ismModelTreeList)
    {
        for (IsmModelTree ismModelTree : ismModelTreeList) {
            ismModelTreeService.insertIsmModelTree(ismModelTree);
        }
        return AjaxResult.success();
    }

    /**
     * 修改模型文件树表
     */
    @PreAuthorize("@ss.hasPermi('tree:tree:edit')")
    @Log(title = "模型文件树表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IsmModelTree ismModelTree)
    {
        return toAjax(ismModelTreeService.updateIsmModelTree(ismModelTree));
    }

    /**
     * 修改模型文件树表
     */
    @PreAuthorize("@ss.hasPermi('tree:tree:edit')")
    @Log(title = "模型文件树表", businessType = BusinessType.UPDATE)
    @PutMapping("/updates")
    public AjaxResult updates(@RequestBody List<IsmModelTree> ismModelTreeList)
    {
        for (IsmModelTree ismModelTree : ismModelTreeList) {
            ismModelTreeService.updateIsmModelTree(ismModelTree);
        }
        return AjaxResult.success();
    }

    /**
     * 删除模型文件树表
     */
    @PreAuthorize("@ss.hasPermi('tree:tree:remove')")
    @Log(title = "模型文件树表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ismModelTreeService.deleteIsmModelTreeByIds(ids));
    }
}
